package org.yaac.client.conf;

import javax.inject.Inject;
import javax.inject.Provider;

import org.yaac.client.activity.BlobActivity;
import org.yaac.client.activity.BrowserActivity;
import org.yaac.client.activity.EGQLActivity;
import org.yaac.client.activity.EditorActivity;
import org.yaac.client.activity.OverviewActivity;
import org.yaac.client.activity.StatisticsActivity;
import org.yaac.client.place.BlobPlace;
import org.yaac.client.place.BrowserPlace;
import org.yaac.client.place.EGQLPlace;
import org.yaac.client.place.EditorPlace;
import org.yaac.client.place.OverviewPlace;
import org.yaac.client.place.StatisticsPlace;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

/**
 * this class performs an "after-init" action to activities by injecting places 
 * 
 * @author Max Zhu (thebbsky@gmail.com)
 * 
 */
public class MainActivityMapper implements ActivityMapper {

	// activity providers
	private final Provider<OverviewActivity> overviewProvider;
	private final Provider<StatisticsActivity> statProvider;
	private final Provider<BrowserActivity> browserProvider;
	private final Provider<EditorActivity> editorProvider;
	private final Provider<EGQLActivity> queryProvider;
	private final Provider<BlobActivity> blobProvider;
	
	@Inject
	public MainActivityMapper(
			Provider<OverviewActivity> overviewProvider,
			Provider<StatisticsActivity> statProvider,
			Provider<BrowserActivity> browserProvider,
			Provider<EditorActivity> editorProvider,
			Provider<EGQLActivity> queryProvider, 
			Provider<BlobActivity> blobProvider) {
		this.overviewProvider = overviewProvider;
		this.statProvider = statProvider;
		this.browserProvider = browserProvider;
		this.editorProvider = editorProvider;
		this.queryProvider = queryProvider;
		this.blobProvider = blobProvider;
	}

	/* (non-Javadoc)
	 * @see com.google.gwt.activity.shared.ActivityMapper#getActivity(com.google.gwt.place.shared.Place)
	 */
	@Override
	public Activity getActivity(Place place) {
	    if (place instanceof OverviewPlace) {
	    	return overviewProvider.get().withPlace((OverviewPlace) place);
	    } else if (place instanceof StatisticsPlace) {
			return statProvider.get().withPlace((StatisticsPlace) place);
	    } else if (place instanceof BrowserPlace) {
			return browserProvider.get().withPlace((BrowserPlace) place);
	    } else if (place instanceof EditorPlace) {
			return editorProvider.get().withPlace((EditorPlace) place);
	    } else if (place instanceof EGQLPlace) {
			return queryProvider.get().withPlace((EGQLPlace) place);
	    } else if (place instanceof BlobPlace) {
			return blobProvider.get().withPlace((BlobPlace) place);
		}

		return null;
	}
}
